package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Test;
import com.woniuxy.entity.TestLabel;
import com.woniuxy.service.TestLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (TestLabel)表控制层
 *
 * @author zjx
 * @since 2021-05-14 19:42:03
 */
@Api(value = "试题标签管理接口")
@RestController
@RequestMapping("testLabel")
public class TestLabelController {
    /**
     * 服务对象
     */
    @Resource
    private TestLabelService testLabelService;

    /**
     * Description : 根据分页条件，查询所有数据，实体类，同时满足模糊查询
     * ChangeLog : 1. 创建 (2021/5/17 10:47 [zjx]);
     * @param map 起始页，每页条数，标签实体类
     * @return null
    */
    @ApiOperation("分页展示试题标签")
    @GetMapping("queryAll")
    public ResponseEntity queryAll(@ApiParam("分页试题类信息")Map<String,Object> map){
        PageInfo<Map<String,String>> pageInfo = this.testLabelService.queryAll(map);
        return new ResponseEntity(200,"success",pageInfo);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public TestLabel selectOne(Integer id) {
        return this.testLabelService.queryById(id);
    }

    /**
     * Description : 插入一条数据
     * ChangeLog : 1. 创建 (2021/5/15 17:29 [zjx]);
     * @param testLabel
     * @return null
     */
    @PostMapping("/insert")
    public ResponseEntity insert(@RequestBody TestLabel testLabel){
        return new ResponseEntity(200,"成功", this.testLabelService.insert(testLabel));
    }
    /**
     * Description : 更新一条数据
     * ChangeLog : 1. 创建 (2021/5/15 17:37 [zjx]);
     * @param testLabel
     * @return null
     */
    @RequestMapping("update")
    public ResponseEntity update(@RequestBody TestLabel testLabel){
        return new ResponseEntity(200,"成功",this.testLabelService.update(testLabel));
    }

    /**
     * Description : 删除一条数据
     * ChangeLog : 1. 创建 (2021/5/15 17:41 [zjx]);
     * @param id
     * @return null
     */
    @DeleteMapping("deleteById")
    public ResponseEntity deleteById(Integer id){

        return new ResponseEntity(200,"成功",this.testLabelService.deleteById(id));
    }

}
